<?php
class What_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
	public function get_what_name(){
		$query = $this->db->get('what');
		$rs = $query->result();
		
		$what_name = array();
		foreach($rs as $row){
			$what_name[$row->id] = $row->name;
		}
		
		return $what_name;
	}
	
	public function strid_to_strname($strid){
		$this->db->select("name");
		$this->db->where_in('id', explode(",", $strid) );
		$rs = $this->db->get("what")->result();
		
		$strname="";
		foreach ($rs as $val) {
			$strname .= ", ".$val->name;
		}
		if ($strname != "") $strname = substr_replace($strname, '', 0, 2);
		//print_r($strname);
		//show_error("");
		return $strname;
	}
	
	public function name2id($name){
		$this->db->select("id");
		$this->db->where("name", $name);
		$rs = $this->db->get("what")->result();
		
		return $rs[0]->id;
	}
}
